<template>
    <base-dialog title="设置" width="600px" v-bind="$attrs" v-on="$listeners" @submit="toSubmit">
        <el-form ref="myForm" :model="formData" label-width="auto" :rules="rules">
            <el-form-item label="是否公开" prop="is_open">
                <el-radio-group v-model="formData.is_open">
                    <el-radio :label="0">否</el-radio>
                    <el-radio :label="1">是</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="发文号">
                <el-autocomplete
                        class="inline-input"
                        v-model="formData.fwh"
                        :fetch-suggestions="querySearch"
                        placeholder="请输入发文号"
                        :style="{width: '45%'}"
                ></el-autocomplete>
                〔
                <el-input v-model="formData.year" placeholder="" :style="{width: '80px'}" clearable
                          class="fwh"></el-input>
                〕
                <el-input v-model="formData.fwz" placeholder="" :style="{width: '80px'}" clearable
                          class="fwh"></el-input>
                号
            </el-form-item>
        </el-form>
    </base-dialog>
</template>
<script>
    import BaseDialog from "@/components/Common/BaseDialog";
    import schoolDocuments from "@/api/officialDocument/schoolDocuments/index"
    export default {
        name:"DocumentSettingDialog",
        components: {BaseDialog},
        props:["id"],
        data(){
            return {
                formData:{
                    is_open:1,
                    year:new Date().getFullYear(),
                    fwh:"",
                    fwz:"",
                },
                rules:{},
                fwhList:[]
            }
        },
        watch:{
        },
        created() {
        },
        methods:{
            toSubmit(){
                this.$refs['myForm'].validate(valid => {
                    if (!valid) return
                    this.getDocumentSaveBh()
                })
            },
            querySearch(queryString, cb) {
                schoolDocuments.getDocumentCategory({search_value:queryString}).then(res => {
                    this.fwhList = res.data.map(item=>{
                        return {value:item.name}
                    })
                    cb(this.fwhList);
                })
            },
            getDocumentSaveBh(){
                schoolDocuments.getDocumentSaveBh(this.id,this.formData).then(res=>{
                    this.$emit("update:visible",false)
                })
            }
        }
    }
</script>
